package Solutions

import "sort"

func hasGroupsSizeX(deck []int) bool {
	var mp = make(map[int]int)
	for _, v := range deck {
		mp[v]++
	}
	var counts = make([]int, 0, len(deck))
	for _, c := range mp {
		counts = append(counts, c)
	}
	sort.Ints(counts)
	if counts[0] == 1 {
		return false
	}
	if len(counts) == 1 && counts[0] != 1 {
		return true
	}
	var div = -1
	for i := 2; i <= counts[0]; i++ {
		if counts[0]%i == 0 && counts[1]%i == 0 {
			div = i
			break
		}
	}
	if div == -1 {
		return false
	}
	for _, v := range counts {
		if v%div != 0 {
			return false
		}
	}
	return true
}
